﻿using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using JM.JCY.Proxy;
using JM.JCY.BusinessEntity.DSJCYD94;
using Microsoft.SharePoint;

namespace JM.JCY.SharePointComponent.LawArchives.PeopleSupervise
{
    public partial class PeopleSuperviseUserControl : UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                SPWeb CurrentWeb = SPContext.Current.Web;
                string _userName = CurrentWeb.CurrentUser.LoginName.ToString().Substring(CurrentWeb.CurrentUser.LoginName.LastIndexOf("|") + 1);

                if (!CommonFunction.GetLawArchivesRole(_userName, 20))
                {
                    this.txtCBR.Text = _userName;
                    this.txtCBR.Enabled = false;
                }

            }
        }

        protected void imgSearch_Click(object sender, ImageClickEventArgs e)
        {

            GridViewDataBind();
        }

        public T_RMJDY_JDAJXXDataSet.T_RYXX20100322DataTable GetRYXXByRYByXM(string XM)
        {
            using (DSJCYD94Proxy proxy = new DSJCYD94Proxy())
            {
                return proxy.GetRYXXByRYByXM(XM);
            }
        }

        protected void gvRMJDY_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            gvRMJDY.PageIndex = e.NewPageIndex;
            GridViewDataBind();
        }
        private void GridViewDataBind()
        {
            string strCBR = this.txtCBR.Text.Trim();
           

            string startDate = "1900-01-01";
            string endDate = "8900-01-01";
            if (!StartDate.IsDateEmpty)
            {
                startDate = StartDate.SelectedDate.ToString("yyyy-MM-dd");
            }

            if (!EndDate.IsDateEmpty)
            {
                endDate = EndDate.SelectedDate.ToString("yyyy-MM-dd");
            }
            
            using (DSJCYD94Proxy proxy = new DSJCYD94Proxy())
            {
                var dt = proxy.GetRMJDYData(strCBR, startDate, endDate);
                this.gvRMJDY.DataSource = dt;
                if (dt.Count > 0)
                {
                    NoRecord.Visible = false;
                }
                else
                {
                    NoRecord.Visible = true;
                }
                this.gvRMJDY.DataBind();
            }
        }

    }
}
